package com.twu.biblioteca.models;


import java.util.Calendar;

public class Movie {

    private Long id;
    private String name;
    private Integer year;
    private String director;
    private Byte rating;
    private boolean checkout;
    private User user;

    public Movie(long id, String name, int year, String director, byte rating, boolean checkout) {
        if(name == null || name.equals("") || director == null || director.equals("")){
            throw new IllegalArgumentException();
        }

        Calendar instant = Calendar.getInstance();
        int instantYear = instant.get(Calendar.YEAR);

        if(year < 0 || year > instantYear){
            throw new IllegalArgumentException();
        }

        this.id = new Long(id);
        this.name = name;
        this.year = new Integer(year);
        this.director = director;
        this.rating = (rating == 0) ? null : new Byte(rating);
        this.checkout = checkout;
        this.user = null;
    }

    @Override
    public String toString() {
        return this.name;
    }

    @Override
    public boolean equals(Object obj) {
        Movie otherMovie = (Movie) obj;

        if(this.id.equals(otherMovie.getId()) && this.name.equals(otherMovie.getName())){
            return true;
        }

        return false;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Integer getYear() {
        return year;
    }

    public String getDirector() {
        return director;
    }

    public Byte getRating() {
        return rating;
    }

    public boolean isCheckout() {
        return checkout;
    }

    public User getUser() {
        return user;
    }

    public void setCheckout(boolean checkout) {
        this.checkout = checkout;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
